package zx.x.modules.yshapp.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zx.x.common.utils.PageUtils;
import zx.x.common.utils.R;
import zx.x.modules.yshapp.entity.CommunityEntity;
import zx.x.modules.yshapp.service.CommunityService;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 *
 * @author x
 * @email x
 */
@RestController
@RequestMapping("yshapp/community")
public class CommunityAppController {
    @Autowired
    private CommunityService communityService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(){
        List<CommunityEntity> list = communityService.list(new QueryWrapper<CommunityEntity>()
                .eq("delete_flag", 0)
                .orderBy(true, false, "cj_time"));

        return R.ok().put("list", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		CommunityEntity communityEntity = communityService.getById(id);

        return R.ok().put("communityEntity", communityEntity);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CommunityEntity communityEntity){
        communityService.save(communityEntity);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CommunityEntity communityEntity){
        communityService.updateById(communityEntity);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        communityService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
